<?php
class Blog_models extends MY_Model
{
	public
		$table = 'blog_records'
		//$prKey = 'users_id',
		//$publishedField = 'faq_status',

	;

	function __construct()
	{
		parent::__construct();

	}

	
	function blog_all($config){
				
		
		if ($this->input->get('per_page'))
		{
			$per_page = $this->input->get('per_page');
		}
		else
		{
			$per_page = 0;
		}
		
		$sql  = ' FROM '.$this->table.' b';
		$sql .= ' WHERE b.br_status=1 ORDER BY b.br_date_posted DESC'; 
		
		$config['total_rows'] = $this->getRowCount($sql);

		$this->pagination->initialize($config); 
		
		$sql = 'SELECT *' . $sql . sprintf(' LIMIT %d, %d', $per_page, $config['per_page']); 

		$this->data['list'] = $this->db->query($sql)->result_array();
	}
	
    function view($br_id){
       
       $sql = "SELECT * FROM blog_records
               WHERE br_id=".$this->db->escape($br_id);

       $result = $this->db->query($sql)->row();
       $this->data['blog_post'] = $result;
       $this->comments($br_id);	

    }
    
  function comments($bc_post_id){
			$sql = "SELECT * FROM blog_comments
               WHERE bc_post_id=".$this->db->escape($bc_post_id)." AND bc_status = 1 ORDER BY bc_date_created DESC";

       $result_comments = $this->db->query($sql)->result_array();
       $this->data['blog_comments'] = $result_comments;
  }
 

}
?>